## Warning: package 'plotly' was built under R version 4.0.3
library(plotly)
if (!require(tidyverse)) install.packages('tidyverse')
library(tidyverse)
if (!require(readxl)) install.packages('readxl')
library(readxl)
burden <- read_excel("Apartment List Data -- Cost Burden 2019.xlsx", skip = 1)
burden <- select(burden, -12)
#View(burden)Insert any text here.
# Rename variables:
namelist <- c("N_Rent_Households",
"Overall_Burden_Rate",
"Moderate_Burden_Rate",
"Severe_Burden_Rate",
"N_Burden_Overall",
"N_Burden_Moderate",
"N_Burden_Severe",
"Median_Rent",
"Median_Renter_Income")
paste(namelist, "18", sep="_")## [1] "N_Rent_Households_18" "Overall_Burden_Rate_18"
## [3] "Moderate_Burden_Rate_18" "Severe_Burden_Rate_18"
## [5] "N_Burden_Overall_18" "N_Burden_Moderate_18"
## [7] "N_Burden_Severe_18" "Median_Rent_18"
## [9] "Median_Renter_Income_18"
names(burden) <- c("Location",
"Type",
paste(namelist, "18", sep="_"),
paste(namelist, "17", sep="_"),
paste(namelist, "08", sep="_"),
paste(namelist, "change_17_18", sep="_"),
paste(namelist, "change_08_18", sep="_"))
named_cities <- burden %>%
filter(Location %in% c("New York, NY",
"Los Angeles, CA",
"San Francisco, CA",
"San Diego, CA",
"Miami, FL",
"Riverside, CA",
"New Orleans, LA",
"Vineland, NJ",
"Ocean City, NJ"))
named_cities <- filter(named_cities, Type == "Metro")
## Put it all together:
myplot <- burden %>%
filter(Type == "Metro" & Median_Renter_Income_18 > 0) %>%
ggplot(aes(x=Median_Renter_Income_18, y=Median_Rent_18, ids = Location)) +
geom_point(aes(color = Overall_Burden_Rate_18)) +
#What we wanted to do was display a line of where 30% income was
#where any point above that line was cost burdened
#and anything below was not. But we couldn't get the line to display
#for us.
geom_line(mapping = aes(x = Median_Renter_Income_18,
y = (Median_Renter_Income_18*.3)/12 ),
color = "white") +
scale_y_log10(breaks = c(500, 1000, 1500, 2000),
labels = c("500", "1K", "1.5K", "2K"),
minor_breaks=NULL) +
labs(title="THE U.S. CITIES WITH\nTHE BIGGEST COST BURDENS",
subtitle=
"Apartment List analyzed which cities have the worst income-to-rent ratios.",
caption = "Source: Apartment List and Yahoo Finance") +
labs(color = "Cost Burden Rate" ) +
xlab("MEDIAN RENTER INCOME 2018") +
ylab("MEDIAN RENT 2018") +
scale_color_gradient(low="yellow", high="red") +
# guides(color=FALSE) +
theme(plot.background = element_rect(fill = "#1F0E42")) +
theme(panel.background = element_rect(fill = "#1F0E42")) +
theme(title = element_text(color = "white")) +
theme(axis.text = element_text(color = "white")) +
theme(plot.title = element_text(hjust=0.5, size = 25)) +
theme(plot.subtitle = element_text(hjust=0.5))
ggplotly(myplot, tooltip = "ids")## geom_path: Each group consists of only one observation. Do you need to adjust
## the group aesthetic?
## png
## 2
…